home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
shells
/
kiss-0.11
/
kiss-0
/
kiss
/
src
/
listoutput.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-23
|
1KB
|
68 lines
#include "kiss.h"
int
nentries = 0;
char
**entry = NULL;
void listoutput (char *buf)
{
entry = xrealloc (entry, (nentries + 1) * sizeof (char *));
entry [nentries++] = xstrdup (buf);
}
void listoutputflush ()
{
/* we can assume that we're in multicolumn mode now */
register int
maxlen = 0,
nperline,
printed = 0,
j,
i;
/* nothing to do? nogo. */
if (! nentries)
return;
/* find longest entry */
for (i = 0; i < nentries; i++)
{
register int
len = strlen (entry [i]);
if (len > maxlen)
maxlen = len;
}
/* allow for extra space */
maxlen++;
nperline = 80 / maxlen;
if (! nperline)
nperline++;
for (i = 0; i < nentries; i++)
{
printf ("%s", entry [i]);
for (j = strlen (entry [i]); j < maxlen; j++)
putchar (' ');
printed++;
if (printed == nperline)
{
putchar ('\n');
printed = 0;
}
}
if (printed)
putchar ('\n');
for (i = 0; i < nentries; i++)
free (entry [i]);
free (entry);
entry = NULL;
nentries = 0;
}